project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

set(RNOH_CPP_DIR "${OH_MODULE_DIR}/@rnoh/react-native-openharmony/src/main/cpp")
set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
add_compile_definitions(WITH_HITRACE_SYSTRACE)
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use

add_subdirectory("${RNOH_CPP_DIR}" ./rn)
set(rtn_calculator_generated_dir "${RNOH_GENERATED_DIR}/rtn_calculator")
file(GLOB_RECURSE rtn_calculator_generated_dir_SRC "${rtn_calculator_generated_dir}/**/*.cpp")
file(GLOB rtn_calculator_package_SRC CONFIGURE_DEPENDS *.cpp)

set(react_native_ocr_generated_dir "${RNOH_GENERATED_DIR}/react_native_ocr")
file(GLOB_RECURSE react_native_ocr_generated_dir_SRC "${react_native_ocr_generated_dir}/**/*.cpp")
file(GLOB react_native_ocr_package_SRC CONFIGURE_DEPENDS *.cpp)

set(rtn_etbridge_generated_dir "${RNOH_GENERATED_DIR}/rtn_etbridge")
file(GLOB_RECURSE rtn_etbridge_generated_dir_SRC "${rtn_etbridge_generated_dir}/**/*.cpp")
file(GLOB rtn_etbridge_package_SRC CONFIGURE_DEPENDS *.cpp)

add_library(rnoh_app SHARED
    ${rtn_calculator_generated_dir_SRC}
    ${rtn_calculator_package_SRC}

    ${react_native_ocr_generated_dir_SRC}
    ${react_native_ocr_package_SRC}

    ${rtn_etbridge_generated_dir_SRC}
    ${rtn_etbridge_package_SRC}

    "./PackageProvider.cpp"
    "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)

target_include_directories(rnoh_app PUBLIC ${rtn_calculator_generated_dir})
target_include_directories(rnoh_app PUBLIC ${react_native_ocr_generated_dir})
target_include_directories(rnoh_app PUBLIC ${rtn_etbridge_generated_dir})
target_link_libraries(rnoh_app PUBLIC rnoh)